-
Notifications
You must be signed in to change notification settings - Fork 0
46. Permutations #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
46. Permutations #50
Conversation
| permuteHelper(result, nums, 0); | ||
| return result; | ||
| } | ||
| void permuteHelper(vector<vector<int>>& result, vector<int>& nums, int decided_until) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private でも問題ないでしょうか。
results は出力なので引数の最後にした方が良いかもしれません。
https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
privateで良いと思います。入れるのを忘れてしまっていました。
出力を最後に持ってくるのが推奨されているというのは知りませんでした。ありがとうございます。
ryosuketc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よいと思います
| permuteHelper(result, nums, 0); | ||
| return result; | ||
| } | ||
| void permuteHelper(vector<vector<int>>& result, vector<int>& nums, int decided_until) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいですが、private 忘れでしょうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あ、失念していました。
| for (int i = decided_until; i < nums.size(); ++i) { | ||
| swap(nums[decided_until], nums[i]); | ||
| permuteHelper(result, nums, decided_until + 1); | ||
| swap(nums[decided_until], nums[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decided_until は swap_index のように感じました。ここまで決めたんだという意味は落ちてしまいますが、、、
| swap(nums[decided_until], nums[i]); | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重複を含む入力に対して正しく(重複は含まれる)動くのはこのコードだけでしょうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかに、その視点はありませんでした。setを使った解法は動かないように思います。
https://leetcode.com/problems/permutations/description/